package com.app.newiptv.helper;

import com.app.newiptv.bean.RequestDto;
import com.app.newiptv.bean.allchannels.Channel;
import com.app.newiptv.bean.allchannels.Program;
import com.app.newiptv.callback.IRequestLisenter;
import com.app.newiptv.callback.RequestCallback;
import com.app.newiptv.utils.OkGoUtil;

import java.util.List;


/**
 * Created by Shinelon on 2017/9/15.
 */

public class ChannelDetailHelper {
    private RequestCallback callback;
    private Channel channel;

    public ChannelDetailHelper() {

    }

    public void setCallback(RequestCallback callback) {
        this.callback = callback;
    }

    public void loadData(String url) {
        OkGoUtil<Channel> okGoUtil = new OkGoUtil<Channel>(Channel.class, OkGoUtil.TYPE_DATA, new IRequestLisenter() {
            @Override
            public void onSuccessData(RequestDto dto) {
                if (dto != null) {
                    channel = (Channel) dto.getData();
                    if (channel != null) {
                        List<Program> programList = channel.getLives();
                        if (callback != null && programList != null) {
                            callback.onLoadComplete("", 0, programList.size(), programList);
                        }
                    }
                }
            }

            @Override
            public void onErrer(int code, String errMsg) {
            }
        });
        okGoUtil.requestGet(url);
    }
}
